package com.desire.homework;

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.Random;

/**
 * @author desire
 */
public class _42_画八卦图形 {
    public static void main(String[] args) {
        int h = 400;
        int w = 400;
        BufferedImage i = new BufferedImage(h, w, 2);
        Graphics2D g = i.createGraphics();
        g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_GASP);
        g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_DEFAULT);
        g.setColor(Color.cyan);
        g.fillRect(0, 0, w, h);

        // 左黑右白俩半圆
        g.setColor(Color.BLACK);
        g.fillArc(50, 50, 300, 300, 90, 180);
        g.setColor(Color.WHITE);
        g.fillArc(50, 50, 300, 300, 90, -180);

        // 小水滴
        g.setColor(Color.WHITE);
        g.fillOval(125, 50, 150, 150);
        g.setColor(Color.BLACK);
        g.fillOval(125, 200, 150, 150);

        // 俩点
        g.setColor(Color.WHITE);
        g.fillOval(150, 237, 75, 75);
        g.setColor(Color.BLACK);
        g.fillOval(150, 87, 75, 75);

        //写字
        Random rand = new Random();
        Font font = new Font("微软雅黑", Font.BOLD, 30);
        g.setColor(Color.RED);
        g.setFont(font);
        g.drawString("新年快乐 更近一步！", 70, 40);

        g.dispose();
        String p = "C:\\Users\\desire\\Desktop\\javaProject\\01-javaBase\\src\\main\\resources\\bagua.png";
        Runtime runtime = Runtime.getRuntime();
        try {
            ImageIO.write(i, "png", new File(p));
            runtime.exec("cmd /k start " + p);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
